#include <func.h>

int main(int argc,char* argv[])
{
    int fields1[2];
    if(pipe(fields1) == -1)
        error(1,errno,"pipe");
    
    int fields2[2];
    if(pipe(fields2) == -1)
        error(1,errno,"pipe");

    char message[256];
    pid_t pid = fork();

    switch(pid)
    {
        case -1:
            error(1,errno,"fork");

        case 0:
            close(fields1[0]);
            close(fields2[1]);

            write(fields1[1],"child:hello!",13);
            read(fields2[0],message,256);
            printf("child get:--%s\n",message);

            break;
        default:
            close(fields1[1]);
            close(fields2[0]);

            sleep(2);
            read(fields1[0],message,256);
            printf("parent get:--%s\n",message);
            write(fields2[1],"parent get message! good!",20);

            break;
    }

    return 0;
}
